home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bchelp10.zip / TI733.ASC < prev    next >
Text File  |  1991-09-18  |  1KB  |  67 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  733
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  September 18, 1991                       PAGE  :  1/1
  12.  
  13.     TITLE  :  How to Use Variable Arguments
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.   /*************************************************************
  22.   Example code for using a variable number of arguments.
  23.   There is only one guaranteed way of accessing arguments passed
  24.   using the ... mechanism.  The standard header file <stdarg.h> as
  25.   specified for ANSI C will provide declarations that can be used
  26.   by a function that does not know the number or types of its
  27.   arguments when it is compiled.
  28.   *************************************************************/
  29.  
  30.   #include <stdarg.h>
  31.   void real_handler(const char*, va_list);
  32.   void my_error_handler(const char* format ...)
  33.   {
  34.       // ...
  35.       va_list ap;
  36.       va_start(ap,format);
  37.       real_handler(format,ap);  /* get arguments */
  38.       va_end(ap);
  39.       exit(99);
  40.   }
  41.  
  42.   void real_handler(const char* format, va_list ap)
  43.   {
  44.       // assume that 'format' tells us that
  45.       // three arguments, a char*, an int, and a double,
  46.       // are passed - in that order - by the va_list 'ap'
  47.       char* p = va_arg(ap,char*);
  48.       int i = va_arg(ap,int);
  49.       double d = va_arg(ap,double);
  50.   }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.